﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SiteFox.Business.Manager
{
    public static class QuickLink
    {
        public static IList<Model.QuickLink> GetByQuickLinks(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.QuickLink where c.ID_QuickLinks == _ID orderby c.Ordering select c;
            return _Query.ToList();
        }
        public static Model.QuickLink GetByID(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.QuickLink where c.ID == _ID select c;
            if (_Query.Count() > 0)
            {
                return _Query.Single();
            }
            else
            {
                return null;
            }
        }
        public static void Create(Model.QuickLink _QuickLink)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            _Entities.AddToQuickLink(_QuickLink);
            _Entities.SaveChanges();
        }
        public static void Edit(Model.QuickLink _QuickLink)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.QuickLink where c.ID == _QuickLink.ID select c;
            var __QuickLink = _Query.Single();
            __QuickLink.Ordering = _QuickLink.Ordering;
            __QuickLink.Target = _QuickLink.Target;
            __QuickLink.Title = _QuickLink.Title;
            __QuickLink.Url = _QuickLink.Url;
            _Entities.SaveChanges();
        }
        public static void Delete(int _ID)
        {
            var _Entities = new Model.Entities(Data.WebConfig.GetConnectionString());
            var _Query = from c in _Entities.QuickLink where c.ID == _ID select c;
            var _QuickLink = _Query.First();
            _Entities.QuickLink.DeleteObject(_QuickLink);
            _Entities.SaveChanges();
        }
    }
}
